package unit5;

import java.lang.reflect.Method;

public class MethodPointerTest {
	public static void main(String[] args)throws Exception {
//		get method pointer to the square and sqrt methods
		Method square=MethodPointerTest.class.getMethod("square", double.class);
		Method sqrt=Math.class.getMethod("sqrt", double.class);
		
//		print tables of x-	and y-values
		printTable(1,10,10,square);
		printTable(1,10,10,sqrt);
		
	}

	private static void printTable(int i, int j, int k, Method f) {
		// TODO Auto-generated method stub
		System.out.println(f);
		double dx=(j-i)/(k-1);
		for(double x=i;x<=j;x+=dx){
			try {
				double y=(double) f.invoke(null, x);
				System.out.printf("%10.4f | %10.4f%n",x,y);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			
		}
	}
	public static double square(double d){
		return d*d;
		
	}
}
